home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / julday.pro < prev    next >
Text File  |  1997-07-08  |  3KB  |  105 lines

  1. ; $Id: julday.pro,v 1.5 1997/01/15 03:11:50 ali Exp $
  2. ;
  3. ; Copyright (c) 1988-1997, Research Systems, Inc.  All rights reserved.
  4. ;    Unauthorized reproduction prohibited.
  5.  
  6. function JULDAY, MONTH, DAY, YEAR, Hour, Minute, Second
  7. ;+
  8. ; NAME:
  9. ;    JULDAY
  10. ;
  11. ; PURPOSE:
  12. ;    Calculate the Julian Day Number for a given month, day, and year.
  13. ;    This is the inverse of the library function CALDAT.
  14. ;    See also caldat, the inverse of this function.
  15. ; CATEGORY:
  16. ;    Misc.
  17. ;
  18. ; CALLING SEQUENCE:
  19. ;    Result = JULDAY(Month, Day, Year)
  20. ;
  21. ; INPUTS:
  22. ;    MONTH:    Number of the desired month (1 = January, ..., 12 = December).
  23. ;
  24. ;    DAY:    Number of day of the month.
  25. ;
  26. ;    YEAR:    Number of the desired year.
  27. ;
  28. ; OPTIONAL INPUT PARAMETERS:
  29. ;    Hour, Minute, Second = optional time of day.
  30. ;
  31. ; OUTPUTS:
  32. ;    JULDAY returns the Julian Day Number (which begins at noon) of the 
  33. ;    specified calendar date.  If the time of day (Hr, Min, Sec), is 0,
  34. ;    the result will be a long integer, otherwise the result is a 
  35. ;    double precision floating point number.
  36. ;
  37. ; COMMON BLOCKS:
  38. ;    None.
  39. ;
  40. ; SIDE EFFECTS:
  41. ;    None.
  42. ;
  43. ; RESTRICTIONS:
  44. ;    Accuracy using IEEE double precision numbers is approximately
  45. ;    1/10000th of a second.
  46. ;
  47. ; MODIFICATION HISTORY:
  48. ;    Translated from "Numerical Recipies in C", by William H. Press,
  49. ;    Brian P. Flannery, Saul A. Teukolsky, and William T. Vetterling.
  50. ;    Cambridge University Press, 1988 (second printing).
  51. ;
  52. ;    AB, September, 1988
  53. ;    DMS, April, 1995, Added time of day.
  54. ;-
  55. ;
  56. ON_ERROR, 2        ; Return to caller if errors
  57.  
  58. MONTHS = ['JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG', $
  59.       'SEP','OCT','NOV','DEC']
  60.  
  61. ; Gregorian Calander was adopted on Oct. 15, 1582
  62. GREG = 15L + 31L * (10L + 12L * 1582L)
  63.  
  64. ; Process the input, if all are missing, use todays date.
  65. NP = n_params()
  66. if NP eq 0 then begin
  67.     DATE = systime()
  68.     L_MONTH = long(where(strupcase(strmid(DATE, 4, 3)) eq MONTHS))
  69.     L_MONTH = L_MONTH[0] + 1    ; Scalarize it...
  70.     L_DAY = long(strmid(DATE, 8, 2))
  71.     L_YEAR = long(strmid(DATE, 20, 4))
  72. endif else if np ge 3 then begin
  73.     L_MONTH = LONG(MONTH)
  74.     L_DAY = LONG(DAY)
  75.     L_YEAR=LONG(YEAR)
  76.     if (L_YEAR eq 0) then message, 'There is no year zero.'
  77. endif else message, 'Wrong number of parameters.'
  78.  
  79.  
  80. if (L_YEAR lt 0) then L_YEAR = L_YEAR + 1
  81. if (L_MONTH gt 2) then begin
  82.     JY = L_YEAR
  83.     JM = L_MONTH + 1
  84.     endif else begin
  85.     JY = L_YEAR - 1
  86.     JM = L_MONTH + 13
  87.     endelse
  88.  
  89. JUL = long(365.25 * JY) + long(30.6001 * JM) + L_DAY + 1720995
  90.  
  91. ; Test whether to change to Gregorian Calandar.
  92. if ((L_DAY + 31L * (L_MONTH + 12L * L_YEAR)) ge GREG) then begin
  93.     JA = long(0.01 * JY)
  94.     JUL = JUL + 2 - JA + long(0.25 * JA)
  95.     endif
  96.  
  97. if n_elements(Hour) + n_elements(Minute) + n_elements(Second) eq 0 then $
  98.     return, JUL
  99. if n_elements(Hour) eq 0 then Hour = 0
  100. if n_elements(Minute) eq 0 then Minute = 0
  101. if n_elements(Second) eq 0 then Second = 0
  102.  
  103. return, JUL + (Hour / 24.0d0) + (Minute/1440.0d0) + (Second / 86400.0d0)
  104. end
  105.